FROM ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive

# 更新和安装包
RUN apt update -y && \
    apt -y install --no-install-recommends apt-utils dialog && \
    apt -y install \
    build-essential \
    clang \
    cmake \
    curl \
    g++ \
    gcc \
    git \
    iproute2 \
    ninja-build \
    poppler-utils \
    procps \
    python3 \
    python3-pip \
    pkg-config \
    sudo \
    tar \
    unzip \
    zip \
    && apt autoremove -y \
    && apt clean -y

# for ubuntu:24.04, there already have a user named `ubuntu` with uid 1000, we need to delete it. see:
# https://askubuntu.com/questions/1513927/ubuntu-24-04-docker-images-now-includes-user-ubuntu-with-uid-gid-1000
RUN touch /var/mail/ubuntu && chown ubuntu /var/mail/ubuntu && userdel -r ubuntu

# 本Dockerfile 添加了一个非root用户`vscode`，具有sudo权限。但是对于Linux，
# 该用户的GID/UID必须与您的本地用户UID/GID匹配，以避免在绑定挂载时出现权限问题。
# 如果您的UID/GID不是1000 请更新USER_UID / USER_GID。有关详细信息，
# 请参阅https://aka.ms/vscode-remote/containers/non-root-user。
ARG USER_UID=1000
ARG USER_GID=1000
ARG USER_NAME=vscode

# 创建一个非root用户
RUN groupadd --gid $USER_GID $USER_NAME \
    && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USER_NAME \
    && echo $USER_NAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USER_NAME \
    && chmod 0440 /etc/sudoers.d/$USER_NAME

# setup vcpkg
RUN git clone --depth=1 \
    --single-branch --branch=master \
    https://github.com/microsoft/vcpkg /home/$USER_NAME/vcpkg \
    && /home/$USER_NAME/vcpkg/bootstrap-vcpkg.sh \
    && /home/$USER_NAME/vcpkg/vcpkg integrate install \
    && /home/$USER_NAME/vcpkg/vcpkg install \
    fmt \
    gtest \
    RapidJSON \
    spdlog

# 切回到dialog模式
ENV DEBIAN_FRONTEND=dialog

# 拷贝Dockerfile到容器中, 以便在容器中查看Dockerfile的源码
COPY Dockerfile /tmp/Dockerfile

# 切换到用户`vscode`
USER $USER_NAME
